package com.sy.controller;

import com.sy.dto.Page;
import com.sy.entity.*;
import com.sy.utils.RedisOperations;
import com.sy.vo.Aggregate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
public class ArticleController extends BaseController {
    @Autowired
    private RedisOperations redisOperations;


    //开始加载所有文章类型集合
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=typeList"})
    public List<Type> getAllType() {
        System.out.println(articleService.getAllType());
        return articleService.getAllType();
    }
    //通过类型id查询类型对象
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=typeById"})
    public Type getTypeByTypeId(Integer typeid) {
        return articleService.getTypeByTypeId(typeid);
    }

    //通过类型id查询所有类型下的信息集合
    @RequestMapping(value = "article", method = RequestMethod.GET,params = {"type=messageListById"})
    public List<Message> getMessageListByTypeId( Integer typeid) {
        return articleService.getMessageListById(typeid);
    }
    //通过类型信息id查询所有信息
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=messageById"})
    public List<Message> getMessageById(  Integer messageid) {
        List<Message>list=new ArrayList<>();
        list.add(articleService.getMessageByTypeId(messageid));
        return list;
    }

    //通过aggregate对象查询所有符合条件的信息集合
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=getMessageListByAggregate"})
    public Page<Message> getMessageListByaggregate(@RequestBody Aggregate aggregate){
        return articleService.getMessageListByaggregate(aggregate);
    }


    //交通类型管理交通信息，交通信息管理交通图片。
    //查询所有交通标志的类型集合
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=trafficList"})
    public List<Trafficsigns> getTrafficSignsList(){
        return articleService.getTrafficSignsList();
    }
    //通过交通类型id查询所有类型下的标志信息集合
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=warnListByTrafficId"})
    public List<Warn> getWarnList(@RequestParam Integer trafficsignsid){
        System.out.println(trafficsignsid);

        return articleService.getWarnList(trafficsignsid);

    }

    //通过交通类型id和交通信息id查询所有的图片集合
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=pictureListByTrafficId"})
    public List<Trafficpiture> getPictureList(@RequestParam Integer trafficsignsid , @RequestParam Integer warnid){
        List<Trafficpiture> list=articleService.getTrafficPictureListByWarnId(trafficsignsid,warnid);
        return list;
    }

    //通过交通类型id查询指定的某个交通信息对象
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=warnByTrafficSignsId"})
    public Warn getWarnByTrafficSingsId(@RequestParam Integer trafficsignsid){
        System.out.println(trafficsignsid);
        Warn warn=articleService.getWarnByTrafficSignsId(trafficsignsid);
        return warn;
    }

    //通过学车指南信息id对观看次数进行改变
    @RequestMapping(value = "article", method = RequestMethod.POST,params = {"type=changeView"})
    public void changeview(@RequestParam Integer messageid){

        articleService.changeViewNumber(messageid);

    }









}